package cn.itcast.bos.base.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.base.dao.AreaDao;
import cn.itcast.bos.base.service.AreaService;
import cn.itcast.bos.domain.base.Area;

@Service
@Transactional
public class AreaServiceImpl implements AreaService {
	@Autowired
	private AreaDao areadao;
	@Override
	public void setAreas(List<Area> list) {
		// TODO Auto-generated method stub
		areadao.save(list);
	}
	
	@Cacheable(value="Area",key="#pageable.pageNumber+'_'+#pageable.pageSize")
	public Page<Area> searchArea(Specification<Area> spec,Pageable pageable){
		Page<Area> findAll = areadao.findAll(spec, pageable);
		return findAll;
	}

	@Override
	public Area findByProvinceAndCityAndDistrict(String[] address) {
		// TODO Auto-generated method stub
		 Area findByProvinceAndCityAndDistrict = areadao.findByProvinceAndCityAndDistrict(address[0],address[1],address[2]);
		 System.out.println(findByProvinceAndCityAndDistrict);
		 return findByProvinceAndCityAndDistrict;
	}

}
